<template>
	<view>
		<view style="background: linear-gradient(#548DFE 60%,#ecf1f3);" class="wid100">
			<image :src="aurl + index_bg" class="wh100" style="height: 380rpx;"></image>
			<view class="wid90 mar borRad20 bacFFF dis disAl foSi28 mar-top20" style="padding: 20rpx 0;justify-content: space-around;">
				<view @click="navTo('/pages/user/report/list')" style="width: 25%;text-align: center;">
					<image src="../../static/shangbao.png" class="borRad50" style="width: 80rpx;height: 80rpx;"></image>
					<view>我的上报</view>
				</view>
				<view v-if="vuex_config['scoreshop_open'] === '1'" @click="navTo('/pages/scoreshop/good/index')" style="width: 25%;text-align: center;">
					<image src="../../static/jifen.png" class="borRad50" style="width: 80rpx;height: 80rpx;"></image>
					<view>积分商城</view>
				</view>
				<view v-if="vuex_config['scoreshop_open'] === '1'" @click="navTo('/pages/user/scorelog')" style="width: 25%;text-align: center;">
					<image src="/static/mingxi.png" class="borRad50" style="width: 80rpx;height: 80rpx;"></image>
					<view>积分明细</view>
				</view>
				<view v-if="vuex_config['scoreshop_open'] === '1'" @click="navTo('/pages/scoreshop/order/list')" style="width: 25%;text-align: center;">
					<image src="/static/jilu.png" class="borRad50" style="width: 80rpx;height: 80rpx;"></image>
					<view>兑换记录</view>
				</view>
			</view>
			<view style="height: 40rpx;"></view>
		</view>
		<view class="wid90 mar borRad10">
			<u-swiper height="180" :list="swiperList" @click="openPage" border-radius="20"></u-swiper>
		</view>
		<view class="wid90 mar mar-top40 borRad20 bacFFF" style="padding: 20rpx 0;">
			<view class="dis disAl disJuB wid90 mar">
				<view class="dis disAl">
					<image src="../../static/wenzhang.png" style="width: 40rpx;height: 40rpx;"></image>
					<view class="mar-left10 fowe600 foSi32">新闻列表</view>
				</view>
				<view class="dis disAl" @click="navTo('/pages/article/index')">
					<view class="mar-right10 foSi28">更多</view>
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
			<block v-for="(item,index) in news_list" :key="index">
				<view class="dis bacFFF borRad10 wid90 mar mar-top20 dis disJuB" @click="navTo('/pages/common/richtext',{id:item.id})">
					<!-- <view class="dis disAl disJuc mar-right20" style="width: 24%;">
						<image :src="aurl + item.cover" style="height: 140rpx;" class="wid100"></image>
					</view> -->
					 <!-- style="width: 75%;" -->
					<view class="dis disJuB fleDir">
						<view class="foSi28 mar-bott20 webkitLineClamp">{{item.title}}</view>
						<view style="color: #a1a1a1;">{{item.createtime}}</view>
					</view>
				</view>
				<view v-if="news_list.length != index+1" class="wid100 mar-top10" style="height: 1rpx ;border-bottom: 1rpx solid #f2f7f8;"></view>
			</block>
			<!-- 空数据 -->
			<!-- <view class="u-u-p-t-80 u-m-t-80 u-p-b-80" v-if="!reportList.length">
				<u-empty text="列表为空" mode="reportList"></u-empty>
			</view> -->
			<!-- 加载更多 -->
			<!-- <view class="u-p-b-30" v-if="reportList.length">
				<u-loadmore :status="has_more ? status : 'nomore'" />
			</view> -->
		</view>
		<!-- <u-back-top :scroll-top="scrollTop"></u-back-top> -->
		<view style="height: 100rpx;"></view>
		<TabBar :current-page="0" />
	</view>
</template>
<script>
	import {BASE_URL,HEADER} from '../../config.js'
	const app = getApp();
	export default {
		data() {
			return {
				swiperList: [],
				config: null,
				reportList: [{},{},{}],
				params: {},
				query: {},
				page: 1,
				status: 'nomore',
				has_more: false,
				is_empty: false,
				scrollTop: 0,
				news_list:[],
				index_bg:'',
				aurl:BASE_URL
			}
		},
		onLoad(options) {
			console.log(options)
			if(options.scene){
				this.hexiao(options.scene)
			}
			this.getPageData();
			// this.navList();
			this.index_list()
			
		},
		onShow() {
			let tmp = uni.getStorageSync('lifeData');
		},
		methods: {
			hexiao(orderid){
				let that = this
				let data = {
					id:orderid
				};
				
				this.$u.api.qr_hx(data).then(res=>{
					if(res.code == 1){
						uni.showModal({
								title: '提示',
								content: '是否确认核销该订单？',
								success: function(res) {
								if (res.confirm) {
								    // 执行确认后的操作
									that.zhx(orderid)
								} 
								
							}
						})
					}else{
						uni.showModal({
								title: '提示',
								content: res.msg,
								showCancel:false,
								success: function(res) {
								if (res.confirm) {
								    // 执行确认后的操作
								
								} 
								
							}
						})
					}
					console.log(res)
				});
				
			},
			zhx(orderid){
				let that = this
				
				let data = {
					id:orderid
				};
				
				this.$u.api.zhx(data).then(res=>{
					uni.showModal({
							title: '提示',
							content: res.msg,
							showCancel:false,
							success: function(res) {
							if (res.confirm) {
							    // 执行确认后的操作
								
							} 
							
						}
					})
					console.log(res)
				});
			},
			index_list: async function() {
				let data = {
					page: this.page,
					...this.params,
					...this.query
				};
				let res = await this.$u.api.index_data(data);
				this.news_list = res.data.new_list
				this.index_bg = res.data.index_img
				console.log('index_list')
				console.log(res)
			},
			async navList() {
				let res = await this.$u.api.navList({
					type: 1
				});
				console.log(res);
				// this.swiperList = res.data.swiper_list;
			},
			async getPageData(cb) {
				let res = await this.$u.api.getPageData({
					page: "indexIndex"
				});
				console.log(res);
				this.swiperList = res.data.swiper_list;
				// this.getList();
				typeof cb == 'function' && cb();
			},
			goShow: function(id) {
				uni.navigateTo({
					url: '/pages/report/show?id=' + id
				})
			},
			openPage(index) {
				let path = this.vuex_config.swiperInfo[index].path;
				if (path == '/' || !path) {
					return;
				}
				if (path.substr(0, 1) == 'p') {
					path = '/' + path;
				}
				if (path.indexOf('http') != -1) {
					this.$u.vuex('vuex_webs', this.vuex_config.swiperInfo[index]);
					this.$u.route('/pages/webview/index');
					return;
				}
				this.$u.route({
					url: path
				});
			},
			previewImage: function(index, i) {
				uni.previewImage({
					urls: this.reportList[index].images_array,
					current: i
				});
			},
			getList: async function() {
				let data = {
					page: this.page,
					...this.params,
					...this.query
				};
				let res = await this.$u.api.getReportOpenList(data);
				this.status = 'nomore';
				uni.stopPullDownRefresh();
				if (!res.code) {
					this.$u.toast(res.msg);
					return;
				}
				if (this.is_update) {
					this.reportList = [];
					this.is_update = false;
				}
				let pageList = res.data;
				this.is_show = true;
				this.has_more = pageList.current_page < pageList.last_page;
				this.reportList = [...this.reportList, ...pageList.data];
				this.is_empty = !this.reportList.length;
			}
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		//下拉刷新
		onPullDownRefresh() {
			this.is_update = true;
			this.page = 1;
			this.getList();
		},
		onReachBottom() {
			if (this.has_more) {
				this.status = 'loading';
				this.page++;
				this.getList();
			}
		},
		onShareAppMessage(res) {
			return {
				title: this.vuex_config.name
			}
		},
		onShareTimeline() {
			return {
				title: this.vuex_config.name
			}
		}
	}
</script>
<style>
	page {
		background-color: #ecf1f3;
	}

	.section {
		padding: 50rpx 50rpx 0 50rpx;
	}

	.go-report {
		display: flex;
		align-items: center;
		border-radius: 20rpx;
		padding: 30rpx;
		background-color: #2196F3;
		color: #fff;
	}

	.left {
		font-size: 32rpx;
		font-weight: 600;
	}

	.go-report .left .u-icon {
		margin-right: 10rpx;
	}

	.go-report .right {
		margin-left: auto;
	}

	.go-report .right .go {
		background-color: #ffffff;
		color: #2196F3;
		padding: 10rpx 30rpx;
		border-radius: 50em;
		font-weight: 600;

	}

	.goSubmitBtn {
		position: fixed;
		width: calc(100% - 60rpx);
		left: 30rpx;
		bottom: 30rpx;
	}
</style>